package com.huajx.cseek.face;

import java.io.ByteArrayOutputStream;
import java.io.DataInputStream;
import java.io.IOException;
import java.net.HttpURLConnection;
import java.net.URL;

import org.slf4j.Logger;
import org.slf4j.LoggerFactory;

import com.ha.facecamera.configserver.pojo.Face;

public class StudentFace {
    private static final Logger logger = LoggerFactory.getLogger(StudentFace.class);

    private String name;//学生姓名

    private String cardId;//考勤卡号

    private String[] path;//图片地址

    private int role;//角色

    private Face face;

    public StudentFace(String name, String cardId, int role, String[] path) {
        this.name = name;
        this.cardId = cardId;
        this.role = role;
        this.path = path;

        this.face = new Face();
        this.face.setId(cardId);
        this.face.setName(name);
        this.face.setRole(role);
        byte[][] jpgFileContent = new byte[path.length][];
        for (int i = 0; i < path.length; i++) {
            byte[] readFile;
            try {
                readFile = QnyfUpload.readFile(path[i]);
            } catch (Exception e) {
                continue;
            }
            if (readFile.length > 0) {
                jpgFileContent[i] = readFile;
            }
        }
        this.face.setJpgFileContent(jpgFileContent);
    }

    public String getName() {
        return name;
    }

    public void setName(String name) {
        this.name = name;
    }

    public String getCardId() {
        return cardId;
    }

    public void setCardId(String cardId) {
        this.cardId = cardId;
    }

    public String[] getPath() {
        return path;
    }

    public void setPath(String[] path) {
        this.path = path;
    }

    public int getRole() {
        return role;
    }

    public void setRole(int role) {
        this.role = role;
    }

    public Face getFace() {
        return face;
    }

    public void setFace(Face face) {
        this.face = face;
    }

//    public byte[] readFile(String path) throws IOException {
//        URL url = new URL(path);
//        HttpURLConnection conn = (HttpURLConnection) url.openConnection();
//        DataInputStream in = new DataInputStream(conn.getInputStream());
//        ByteArrayOutputStream out = new ByteArrayOutputStream();
//        byte[] buffer = new byte[1024 * 4];
//        int n = 0;
//        while ((n = in.read(buffer)) != -1) {
//            out.write(buffer, 0, n);
//        }
//        byte[] byteArray = out.toByteArray();
//        return out.toByteArray();
//    }

}
